package com.song.shenghua.match.controller;

import cn.hutool.core.date.DateUtil;
import com.song.shenghua.common.core.domain.AjaxResult;
import com.song.shenghua.common.utils.uuid.IdWorker;
import com.song.shenghua.match.domain.MatchHealth;
import com.song.shenghua.match.service.IMatchHealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author 宋LS
 * @version 1.0
 * @date 2021/3/7 22:27
 */

@RestController
@RequestMapping("test")
public class testController {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private IMatchHealthService healthService;

    @RequestMapping("testredis/{uid}")
    public AjaxResult testRedis(@PathVariable("uid") String uid) {
        MatchHealth health = new MatchHealth();
        health.setCough(1);
        health.setDatatime(new Date());
        health.setHumidity(50.0);
        health.setTemperature(36.5);
        health.setUid(uid);
        health.setEquipmentId("123456789");

        Set keys = redisTemplate.opsForHash().keys(uid);
        Map map = new HashMap();
        map.put("banzi", health);
        map.put("当前在线用户", keys);

        IdWorker idWorker = new IdWorker(11, 11);
        health.setId(idWorker.nextId());
        healthService.insertMatchHealth(health);


        return AjaxResult.success(map);
    }

    @RequestMapping("test/{day}")
    public String testss(@PathVariable("day") int day) {
        MatchHealth matchHealth = new MatchHealth();

        Random random = new Random();
        for (int i = 0; i < 7; i++) {
            day++;
            int finalDay = day;
            for (int j = 0; j < 24; j++) {
                for (int k = 0; k < 60; k++) {
                    String dateStr = "2021-03-0" + finalDay + " " + j + ":" + k + ":00";
                    Date date = DateUtil.parse(dateStr, "yyyy-MM-dd HH:mm:ss");
                    matchHealth.setTemperature(36 + (random.nextInt(10) / 10.0));
                    matchHealth.setHumidity(random.nextInt(100) * 1.0);
                    matchHealth.setUid("1767821837");
                    IdWorker idWorker = new IdWorker(random.nextInt(10), random.nextInt(15));
                    matchHealth.setId(idWorker.nextId());
                    matchHealth.setEquipmentId("123456789");
                    matchHealth.setCough(random.nextInt(2));
                    matchHealth.setDatatime(date);
                    healthService.insertMatchHealth(matchHealth);
                }
            }

        }


        return "成功";
    }
@RequestMapping("addday/{finalDay}")
    public void addday(@PathVariable("finalDay") String finalDay) {
        MatchHealth matchHealth = new MatchHealth();
        Random random = new Random();
        for (int j = 0; j < 24; j++) {
            for (int k = 0; k < 60; k++) {
                String dateStr = "2021-03-0" + finalDay + " " + j + ":" + k + ":00";
                Date date = DateUtil.parse(dateStr, "yyyy-MM-dd HH:mm:ss");
                matchHealth.setTemperature(36 + (random.nextInt(10) / 10.0));
                matchHealth.setHumidity(random.nextInt(100) * 1.0);
                matchHealth.setUid("1767821837");
                IdWorker idWorker = new IdWorker(random.nextInt(10), random.nextInt(15));
                matchHealth.setId(idWorker.nextId());
                matchHealth.setEquipmentId("123456789");
                matchHealth.setCough(random.nextInt(2));
                matchHealth.setDatatime(date);
                healthService.insertMatchHealth(matchHealth);

            }
        }
    }
//
}


